Imports System.Data
'Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
' Para gerar Excel
Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.Office.Interop

Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

' Para gerar Excel
Imports System.Reflection
Imports System.Runtime.InteropServices

Partial Class ImpRelRateioDeDespesas
    Inherits System.Web.UI.Page

    '    Private Function CarregaGVWDetail(ByVal strMesAnoDeCompetencia As String, ByVal strCodigoDaCia As String) As Boolean

    '        Dim conn As New MySqlConnection("Database=liion;Data Source=localhost;User Id=" & Session("strUserID") & ";Password=" & Session("strPassWord"))
    '        Dim adapter As New MySqlDataAdapter()
    '        Dim dataSet As New DataSet()
    '        Dim strSQL As String
    '        Dim strWhere As String = ""

    '        CarregaGVWDetail = False

    '        Try
    '            strSQL = "SELECT CodigoDaHolding, CodigoDaCia, CodigoDoEstabelecimento," & _
    '                     " NumeroDoRegistroDoEmpregado, NomeDoEmpregado," & _
    '                     " MesAnoDeCompetencia, CodigoDoCentroDeCusto," & _
    '                     " Salario, SalarioConvertido, PorcentagemDeParticipacao," & _
    '                     " PercentualDaAtividade, CodigoDaCiaNaAtividade," & _
    '                     " ValorParaRateio, CodigoDaConta," & _
    '                     " ValorCalculadoPorContaContabil, ValorCalculadoDoRateio" & _
    '                     " FROM v_RateioDeDespesas" & _
    '                     " WHERE CodigoDaCia = '" & Session("strCodigoDaCia").ToString & "'" & _
    '                     " AND MesAnoDeCompetencia = '" & Session("strMesAnoDeCompetencia").ToString & "'" & _
    '                     " ORDER BY CodigoDoCentroDeCusto, NumeroDoRegistroDoEmpregado, CodigoDaConta;"

    '            adapter.SelectCommand = New MySqlCommand(strSQL, conn)
    '            adapter.Fill(dataSet)

    '            gvwDetail.DataSource = dataSet
    '            gvwDetail.DataBind()

    '            CarregaGVWDetail = True

    '        Catch ex As Exception
    '            Session.Add("MsgException", ex.Message)
    '            'If Request.IsLocal Then
    '            '    Session("CurrentError") = ex.Message
    '            'Else
    '            '    Session("CurrentError") = "Error processing page."
    '            'End If
    '            'Server.Transfer("Login.aspx")
    '        Finally
    '            conn.Close()
    '        End Try

    '    End Function

    '    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    '        Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache)

    '        If Not Page.IsPostBack Then

    '            Dim strConnection As String = ""

    '            strConnection = "Database=liion;Data Source=localhost;User Id=" & Session("strUserID") & ";Password=" & Session("strPassWord")

    '            'btnImprimir.Enabled = False

    '            If (CarregaGVWDetail(Session("strMesAnoDeCompetencia").ToString, Session("strCodigoDaCia").ToString) = True) Then

    '                If (gvwDetail.PageCount = 0) Then
    '                    Response.Redirect("RelRateioDeDespesas.aspx")
    '                Else
    '                    If (Not (ExportaExcel01() = True)) Then

    '                    End If
    '                    'Response.Redirect("RelPesoDoEmpregadoNoCentroDeCusto.aspx")
    '                End If
    '            End If
    '        End If

    '    End Sub

    '    Private Function ExportaExcel01() As Boolean

    '        ExportaExcel01 = False

    '        Try
    '            Dim frm As HtmlForm = New HtmlForm

    '            'gvwData.AllowPaging = False
    '            'gvwData.DataBind()

    '            Response.Clear()
    '            Response.AddHeader("content-disposition", "attachment; filename=FileName.xls")
    '            Response.Charset = ""
    '            'Response.ContentType = "application/vnd.xls"
    '            Response.ContentType = "application/vnd.ms-excel"

    '            ' If you want the option to open the Excel file without saving than comment out the line below
    '            Response.Cache.SetCacheability(HttpCacheability.NoCache)

    '            'Response.ContentType = "application/vnd.xls"

    '            'gvwData.Page.EnableViewState = False
    '            EnableViewState = False
    '            'Controls.Add(frm)
    '            'frm.Controls.Add(gvwData)

    '            'Dim strBuilder As New StringBuilder("")
    '            Dim stringWrite As New StringWriter()
    '            'System.IO.StringWriter(stringWrite = New System.IO.StringWriter())

    '            Dim htmlWrite As New HtmlTextWriter(stringWrite)
    '            'System.Web.UI.HtmlTextWriter(htmlWrite = New HtmlTextWriter(stringWrite))

    '            'frm.RenderControl(htmlWrite)
    '            gvwDetail.RenderControl(htmlWrite)

    '            Response.Write(stringWrite.ToString())

    '            Response.End()

    '            ExportaExcel01 = True
    '            'gvwData.AllowPaging = True
    '            'gvwData.DataBind()

    '        Catch ex As Exception
    '            'lblMsg.Text = ex.Message
    '        End Try

    '    End Function

End Class
